package org.hiucung.lib_base.helper

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat

/**
 * @title: NotificationHelper
 * @projectName OrangeAiVoiceApp
 * @description: TODO
 * @author Kicc
 * @date 2021/11/19 13:45
 */
object NotificationHelper {
    private lateinit var mContext : Context
    private lateinit var nm : NotificationManager

    private const val CHANNEL_ID = "orange_ai_voice_service"
    private const val CHANNEL_NAME = "语言服务"

    fun initHelper(mContext : Context){
        this.mContext = mContext
        nm = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        setBindVoiceChannel()
    }

    fun setBindVoiceChannel(){
        //安卓8.0之后创建渠道
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){

            val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME,NotificationManager.IMPORTANCE_HIGH)

            //呼吸灯
            channel.enableLights(false)
            //振动
            channel.enableVibration(false)
            //角标
            channel.setShowBadge(false)
            nm.createNotificationChannel(channel)
        }
    }

    fun bindVoiceService(contentText : String) : Notification{
        //安卓8.0之后需要传入渠道id
        var notificationCompat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationCompat.Builder(mContext, CHANNEL_ID)
        }else{
            NotificationCompat.Builder(mContext)
        }

        notificationCompat.setContentTitle(CHANNEL_NAME)

        notificationCompat.setContentText(contentText)

        notificationCompat.setWhen(System.currentTimeMillis())

        //禁止滑动删除通知
        notificationCompat.setAutoCancel(false)

        return notificationCompat.build()
    }
}